$(document).ready(function(){
   
    //礼包列
    var htmlgame = '';
    var listgame = [];
    listgame = [
        {
            gamenamemin:'twcq',
            gameimg:'images/twcq.png',
            gamename:'天王传奇',
            gametitle:'十倍爆率，自动打怪，元宝回收',
            gifts:[
                {
                    giftname:'新手礼包1-1',
                    giftminname:'twcq',
                    giftcard:'tanwan666',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'gycq',
            gameimg:'images/gycq.png',
            gamename:'公益传奇',
            gametitle:'怪物好打，装备好爆，元宝回收',
            gifts:[
                {
                    giftname:'新手礼包2-1',
                    giftminname:'gycq',
                    giftcard:'888888',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'wcyx',
            gameimg:'images/wcyx.png',
            gamename:'王城英雄',
            gametitle:'超变传奇，十倍爆率，小怪好打，装备好爆',
            gifts:[
                {
                    giftname:'新手礼包3-1',
                    giftminname:'wcyx',
                    giftcard:'wcyx888',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'xj',
            gameimg:'images/xj.png',
            gamename:'仙禁',
            gametitle:'角色任意转职，入圣成魔由你来定',
            gifts:[
                {
                    giftname:'新手礼包3-1',
                    giftminname:'xj',
                    giftcard:'602laiba',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'rxwl',
            gameimg:'images/rxwl.png',
            gamename:'热血武林',
            gametitle:'注册有礼，装备全爆',
            gifts:[
                {
                    giftname:'新手礼包3-1',
                    giftminname:'rxwl',
                    giftcard:'rx666',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        },
        {
            gamenamemin:'ljsm',
            gameimg:'images/ljsm.png',
            gamename:'灵剑山盟',
            gametitle:'一剑东来，万剑归宗，仙本无道',
            gifts:[
                {
                    giftname:'新手礼包3-1',
                    giftminname:'ljsm',
                    giftcard:'1a19965ccdcb',
                    giftText:'元宝*200、神秘钥匙*1、经脉丹*10、野外BOSS卷*5'
                }
            ]
        }
    ];
    if(listgame.length<1){
        // console.log("小于一")
    }else{
        // console.log("大于一")
        
        for(var i=0;i<listgame.length;i++){
            var gifts = listgame[i].gifts;
            var htmlgift = '';            
            htmlgame += '<div class="planCenBox">'+
                            '<div class="planImg"><img src="'+listgame[i].gameimg+'" /></div>'+
                            '<div class="planCen">'+
                                '<p>'+listgame[i].gamename+'<span class="planhot"></span></p>'+
                                '<p>'+listgame[i].gametitle+'</p>'+
                            '</div>'+
                            '<div class="palnBtn">'+
                                '<button onclick="enterGame(\''+listgame[i].gamenamemin+'\')">开始</button>'+
                            '</div>'+
                            '<div class="giftBoxs">'
                            if(gifts.length<1){
                            }else{
                                for(var j =0;j<gifts.length;j++){
                                    htmlgift += '<div class="giftBox">'+
                                                    '<div class="giftBoxLeft">'+
                                                        '<i></i>'+
                                                        '<p>'+gifts[j].giftname+'</p>'+
                                                    '</div>'+
                                                    '<div class="giftBoxRight">'+gifts[j].giftText+'</div>'+
                                                    '<div class="gitgift" onclick="gitgift(\''+gifts[j].giftminname+'\')">'+
                                                        '<a><img src="images/gift_right.png" /></a>'+
                                                    '</div>'+
                                                '</div>'
                                }                
                            }
            htmlgame += htmlgift;
            htmlgame += '</div>'+
                            '<div class="more">'+
                                '<p><span>更多礼包('+gifts.length+')</span><samp></samp></p>'+
                            '</div>'+
                        '</div>'
        }        
        $(".playBox").html(htmlgame)        
    };

    $(".more").click(function(){
        $(this).siblings(".giftBoxs").toggle()
    });

     //点击重加载
     $('.reload').click(function(){
        alert('测试重加载')
    })

})

//领取礼包
function gitgift(obj){
    $(".bouncedBg").addClass('disb').removeClass('disn')
    var htmlgift='<button onclick="enterGame(\''+obj+'\')">进游戏兑换</button>';
    if(obj=='twcq'){ //天王传奇
        $('#giftcard').val('tanwan666')
        $('.togameBtnBox').html(htmlgift)
    }
    if(obj=='gycq'){ //公益传奇
        $('#giftcard').val('888888')
        $('.togameBtnBox').html(htmlgift)
    }
    if(obj=='wcyx'){ //王城英雄
        $('#giftcard').val('wcyx888')
        $('.togameBtnBox').html(htmlgift)
    }
    if(obj=='xj'){ //仙禁
        $('#giftcard').val('602laiba')
        $('.togameBtnBox').html(htmlgift)
    }
    if(obj=='rxwl'){ //热血武林
        $('#giftcard').val('rx666')
        $('.togameBtnBox').html(htmlgift)
    }
    if(obj=='ljsm'){ //灵剑山盟
        $('#giftcard').val('1a19965ccdcb')
        $('.togameBtnBox').html(htmlgift)
    }
}
//关闭弹框
function closegit(){
    $(".bouncedBg").addClass('disn').removeClass('disb')
}